package com.vgmobile.cucrever2.home;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.vgmobile.cucrever2.R;
import com.vgmobile.cucrever2.global.BaseActivity;

public final class HomeEventFragment extends Fragment {

	private String linkImage;
	private ImageView imageView;
	private BaseActivity activity;

	public static HomeEventFragment newInstance(String image) {
		HomeEventFragment fragment = new HomeEventFragment();
		fragment.linkImage = image;
		return fragment;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		activity = (BaseActivity) getActivity();
		View view = inflater.inflate(R.layout.home_event_item, null);
		imageView = (ImageView) view.findViewById(R.id.store_event_image);
		imageView.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				
			}
		});
    	activity.loadImage(imageView, linkImage);
		return view;
	}
	
	@Override
	public void onDestroyView() {
//		Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
//		bitmap.recycle();
//		bitmap = null;
//		unbindDrawables(imageView);
		Log.d("--------", "+++++");
		super.onDestroyView();
	}
    
	private void unbindDrawables(View view) {
		try{
	        if (view.getBackground() != null) {
	        	view.getBackground().setCallback(null);
	        }
	        if (view instanceof ViewGroup) {
	            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
	            	unbindDrawables(((ViewGroup) view).getChildAt(i));
	            }
	            try{
	            	((ViewGroup) view).removeAllViews();
	            }catch (Exception e) {
					// TODO: handle exception
				}
	        }
		}catch (Exception e) {
			// TODO: handle exception
		}
	}
}
